package com.bulls.demo.hrmsdemo.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.bulls.demo.hrmsdemo.constants.Constants;
import com.bulls.demo.hrmsdemo.db.Person;
import com.bulls.demo.hrmsdemo.form.LoginForm;
import com.bulls.demo.hrmsdemo.form.SignupForm;
import com.bulls.demo.hrmsdemo.helper.SignupHelper;
import com.bulls.demo.hrmsdemo.service.LoginService;
import com.bulls.demo.hrmsdemo.service.SignupService;

public class SignupAction extends Action {
	
	public ActionForward execute(ActionMapping actionMapping,ActionForm actionForm,
			 HttpServletRequest request,HttpServletResponse response)
		throws Exception{
		String forwardPath="";
		SignupForm form = (SignupForm) actionForm; 
		String command = request.getParameter("cmd");
		System.out.println("cmd"+command);
		if(Constants.CMD_OPEN.equals(command)){
			forwardPath = executeOpen(request,response,form);
		}else{
			Person person = new Person();
			SignupHelper.toDomainObject(form, person);
			person = getSignupService().save(person);
		}
		return actionMapping.findForward(forwardPath);
	}

	private String executeOpen(HttpServletRequest request,
			HttpServletResponse response, SignupForm form) {
		
		return "open";
		// TODO Auto-generated method stub
		
	}
	
	public SignupService getSignupService(){
		SignupService signupService = new SignupService();
		return signupService;
	}
}
